lib: Port variant-builder.c to new style
authorColin Walters <walters@verbum.org>
Fri, 18 Oct 2019 14:56:51 +0000 (14:56 +0000)
committerColin Walters <walters@verbum.org>
Fri, 18 Oct 2019 15:07:39 +0000 (15:07 +0000)
Seeing `scan-build` warning here, prep for fixing it.

src/libotutil/ot-variant-builder.c

index 5b331e62a2c26c2299902af1ce54347b54c73452..6636068e6e3832b2ae1395aa784dc5c2b99af97b 100644 (file)
@@ -1150,14 +1150,8 @@ ot_variant_builder_end (OtVariantBuilder *builder,
                         GError **error)
 {
   OtVariantBuilderInfo *info = builder->head;
-  gsize total_size;
-  gsize offset_size;
-  int i;
-  g_autofree guchar *offset_table = NULL;
-  gsize offset_table_size;
   gboolean add_offset_table = FALSE;
   gboolean reverse_offset_table = FALSE;
-  guchar *p;
 
   g_return_val_if_fail (info->n_children >= info->min_items,
                         FALSE);
@@ -1188,15 +1182,14 @@ ot_variant_builder_end (OtVariantBuilder *builder,
 
   if (add_offset_table)
     {
-      total_size = gvs_calculate_total_size (info->offset, info->child_ends->len);
-      offset_size = gvs_get_offset_size (total_size);
-
-      offset_table_size = total_size - info->offset;
-      offset_table = g_malloc (offset_table_size);
-      p = offset_table;
+      const gsize total_size = gvs_calculate_total_size (info->offset, info->child_ends->len);
+      const gsize offset_size = gvs_get_offset_size (total_size);
+      const gsize offset_table_size = total_size - info->offset;
+      g_autofree guchar *offset_table = g_malloc (offset_table_size);
+      guchar *p = offset_table;
       if (reverse_offset_table)
         {
-          for (i = info->child_ends->len - 1; i >= 0; i--)
+          for (int i = info->child_ends->len - 1; i >= 0; i--)
             {
               gvs_write_unaligned_le (p, g_array_index (info->child_ends, guint64, i), offset_size);
               p += offset_size;
@@ -1204,7 +1197,7 @@ ot_variant_builder_end (OtVariantBuilder *builder,
         }
       else
         {
-          for (i = 0; i < info->child_ends->len; i++)
+          for (int i = 0; i < info->child_ends->len; i++)
             {
               gvs_write_unaligned_le (p, g_array_index (info->child_ends, guint64, i), offset_size);
               p += offset_size;